'use client'; import { useState, type FormEvent } from 'react'; import { ORDER_MESSAGE_LIMIT } from '@/app/lib/order-messages'; export function ApproveForm({ orderId, generationId }: { orderId: string; generationId: string | null }) { const [termsAccepted, setTermsAccepted] = useState(false); const [mode, setMode] = useState<'idle' | 'approving' | 'revising'>('idle'); const [reviseNote, setReviseNote] = useState(''); const [error, setError] = useState(null); const [showRevise, setShowRevise] = useState(false); const onApprove = async (e: FormEvent) => { e.preventDefault(); if (!termsAccepted) return; setMode('approving'); setError(null); try { const res = await fetch(`/api/orders/${orderId}/approve`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ termsAccepted: true, generationId }), }); if (!res.ok) { const data = await res.json().catch(() => null) as { error?: string } | null; throw new Error(data?.error ?? `Approve failed (${res.status})`); } // Payment was collected at /checkout up-front, so approving is // purely a confirmation. Send the customer to their order page // where the "approved" status copy explains the studio review // step before printing. window.location.href = `/orders/${orderId}?approved=1`; } catch (e) { setError(e instanceof Error ? e.message : 'Approve failed'); setMode('idle'); } }; const onRevise = async (e: FormEvent) => { e.preventDefault(); if (!reviseNote.trim()) return; setMode('revising'); setError(null); try { const res = await fetch(`/api/orders/${orderId}/revise`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ note: reviseNote.trim(), generationId }), }); if (!res.ok) { const data = await res.json().catch(() => null) as { error?: string } | null; throw new Error(data?.error ?? `Revision failed (${res.status})`); } const data: { emailSent?: boolean } = await res.json(); window.location.href = `/orders/${orderId}?revised=${data.emailSent === false ? 'saved' : '1'}`; } catch (e) { setError(e instanceof Error ? e.message : 'Revision failed'); setMode('idle'); } }; return (
Approving your portrait is final.

Once you approve, we send your file to our print partner. Each piece is made-to-order for your pet — printed, framed, and hand-finished. Because we can’t restock or resell a custom commission,{' '} all approved orders are non-refundable.

Before this point you can request free revisions until the artwork is right.

— or —
{!showRevise ? ( ) : (

We start with the proof you’re reviewing. Tell us what to change and what you’d like to keep. For example, you can ask for a simpler background, warmer colour, or a tighter crop. Small details may shift between versions.